import sys

from peewee_migrate import Router

from app.advices import models as advices_models
from app.auth import models as auth_models
from db.base_model import db
from app.demo import models as demo_models
from app.text import models as text_models
from app.version import models as version_models

# 需要迁移的数据库表, 所有数据新增、修改的都需要引入
migrate_tables = [demo_models, auth_models, text_models, version_models, advices_models]

def create_migrate():
    db.connect()
    router = Router(db, ignore="basemodel")
    router.create(auto=migrate_tables)
    print("表迁移文件生成完成！！")
    db.close()


def run_migrate():
    db.connect()
    router = Router(db, ignore="basemodel")
    router.run()
    print("表迁移至数据库完成！！")
    db.close()


if __name__ == "__main__":
    action = sys.argv[1]
    if action == "run_migrate":
        run_migrate()
    elif action == "create_migrate":
        create_migrate()
